package ms.unicorn.erml.helper;

import ms.unicorn.Element;
import ms.unicorn.Relation;
import ms.unicorn.erml.ERML;
import ms.unicorn.modellanguage.LanguageRelationEditHelperAdvice;

public class CompositionRelationHelperAdvice extends
		LanguageRelationEditHelperAdvice {

	public CompositionRelationHelperAdvice() {

	}

	@Override
	public boolean checkRelationConstraints(Element container,
			Relation linkInstance, Element source, Element target) {

		String srcType = source != null ? source.getElementType() : null;
		// String tarType = target != null ? target.getElementType() : null;

		if (ERML.COMPOSITION_HUB_ID.equals(srcType)) {
			if (source.getOutgoing().size() > 0
					&& source.getOutgoing().indexOf(linkInstance) < 0)
				return false;
		}

		return super.checkRelationConstraints(container, linkInstance, source,
				target);
	}

}
